<?php
namespace app\api\controller\v1;
use think\Controller;
use think\Db;

class Enrollment extends Controller
{
    // 不需要登录和权限验证
    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';

    /**
     * 获取报名详情
     */
    public function getEnrollmentDetail()
    {
        // 获取请求参数中的项目 ID
        $id = input('id/d'); // 获取项目 ID（整数类型）

        if (!$id) {
            return json(['code' => 400, 'msg' => '缺少项目 ID']);
        }

        // 查询项目表
        $info = Db::name('course_table_autoplan_temp')
            ->alias('t')
            ->join('fa_course_table tb', 'tb.id=t.table_id', 'INNER')
            ->join('eb_school s', 'tb.school_id=s.id', 'INNER')
            ->join('eb_classes c', 'c.id=t.classes_id', 'INNER')
            ->join('fa_ocation o', 'o.id=t.ocation_id', 'INNER')
            ->join('fa_ocation o2', 'o.pid=o2.id', 'INNER')
            ->field("c.id,tb.name as project_name,tb.start_date,tb.end_date,s.name as school_name,c.num,c.intro,c.credit_exchange,c.description,c.num-apply_num as remaining_slots,o2.name as ocation_name,c.name as className,c.cover,subjectlv_id_b,c.price,tb.start_date")
            ->where('c.id', $id)
            ->group("t.ocation_id,t.classes_id")
            ->select();

        if (!$info) {
            return json(['code' => 404, 'msg' => '事项不存在']);
        }

        return json([
            'code' => 200,
            'msg' => 'success',
            'data' => $info
        ]);
    }

    /**
     * 获取招生简章列表
     */
    public function getEnrollmentList()
    {
        $id = input('id/d');
        // 查询招生简章表
        $enrollmentList = Db::name('course_table_autoplan_temp')
            ->alias('t')
            ->join('fa_course_table tb', 'tb.id=t.table_id', 'INNER')
            ->join('eb_school s', 'tb.school_id=s.id', 'INNER')
            ->join('eb_classes c', 'c.id=t.classes_id', 'INNER')
            ->join('fa_ocation o', 'o.id=t.ocation_id', 'INNER')
            ->join('fa_ocation o2', 'o.pid=o2.id', 'INNER')
            ->field("c.id,tb.name as project_name,tb.start_date,tb.end_date,s.name as school_name,c.num,c.intro,c.credit_exchange,c.description,c.num-apply_num as remaining_slots,o2.name as ocation_name,c.name as className,c.cover,subjectlv_id_b,c.price,tb.start_date")
            ->where('s.id', $id)
            ->group("t.ocation_id,t.classes_id")
            ->select();

        if (!$enrollmentList) {
            return json(['code' => 404, 'msg' => '该学校的招生事项不存在']);
        }

        return json([
            'code' => 200,
            'msg' => 'success',
            'data' => $enrollmentList
        ]);
    }
}